package com.cater.project.service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.project.dao.DemandCommunicateDao;
import com.cater.project.entity.DemandCommunicate;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.DictionarydataDao;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.BaseService;

/**
 * 描述：沟通记录 服务实现层
 * 
 * @author yong
 * @date 2018/06/11
 */
@Service
public class DemandCommunicateServiceImpl implements BaseService<DemandCommunicate, CommonQuery, String> {

	@Autowired
	DemandCommunicateDao dao;
	@Autowired
	DictionarydataDao dictDao;

	@Override
	public PageResult<DemandCommunicate> findPageResult(CommonQuery query) {
		PageResult<DemandCommunicate> result = new PageResult<DemandCommunicate>();
		Dictionarydata dictClassid = new Dictionarydata();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<DemandCommunicate> list = dao.findList(query, first, max);
		for (DemandCommunicate t : list) {
			String classid = t.getClassid();
			if (StringUtils.isNotEmpty(classid)) {
				dictClassid = dictDao.getByTypeValue(classid, "resume_status");
				t.setDictClass(dictClassid.getValueName());
			} else {
				t.setDictClass("无");
			}
		}
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<DemandCommunicate> getAll() {
		return dao.getAll();
	}

	@Override
	public List<DemandCommunicate> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(DemandCommunicate t) {
		return 0;
	}

	@Override
	public String saves(DemandCommunicate t) {
		t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(DemandCommunicate t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public DemandCommunicate getById(String id) {
		return dao.getById(id);
	}

	public List<DemandCommunicate> getListBytelentsId(CommonQuery query) {
		return dao.getListBytelentsId(query);
	}

	public List<Map<String, String>> getCommunicateForIndex(CommonQuery query) {
		return dao.getCommunicateForIndex(query);
	}

	public List<Map<String, String>> getCommunicateForMsg(CommonQuery query) {
		return dao.getCommunicateForMsg(query);
	}

	public List<DemandCommunicate> getListBy(CommonQuery query) {
		return dao.getListBy(query);
	}

	public List<DemandCommunicate> getByDemandId(String demandId) {
		return dao.getByDemandId(demandId);
	}

	public List<DemandCommunicate> getByRecommandId(String recommendId) {
		return dao.getByRecommandId(recommendId);
	}

	public List<Map<String, String>> getCount(CommonQuery query) {
		return dao.getCount(query);
	}
}